package com.cecil.generate.service;

import com.cecil.generate.constants.GlobalProperties;
import com.cecil.generate.domain.Column;
import com.cecil.generate.domain.Table;
import com.cecil.generate.mapper.DatabaseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DatabaseService {

    @Autowired
    private DatabaseMapper mapper;
    @Autowired
    private GlobalProperties globalProperties;

    public List<Column> findColumn(String dbName, String tableName) {
        return mapper.findColumn(dbName, tableName);
    }

    public Table findTable(String dbName, String tableName) {
        return mapper.findTable(dbName, tableName);
    }

    public List<Table> findTableList(String dbName) {
        return mapper.findTableList(dbName);
    }

    public List<Table> findByDbNameTableNames(String dbName, List<String> tableNames) {
        List<Table> tables = mapper.findByDbNameTableNames(dbName, tableNames);
        tables.forEach(table -> table.updateProp(globalProperties));
        return tables;
    }
}
